package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单界面
 */
public class MenuPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon saveImg = new ImageIcon("images/buttonSave.jpg");
    private ImageIcon getImg = new ImageIcon("images/buttonGet.jpg");
    private ImageIcon searchImg = new ImageIcon("images/buttonFind.jpg");
    private ImageIcon changePwdImg = new ImageIcon("images/buttonModify.jpg");
    private ImageIcon transFerImg = new ImageIcon("images/buttonTransfer.jpg");
    private ImageIcon offImg = new ImageIcon("images/buttonOff.jpg");
    private JButton saveBtn = new JButton(saveImg);
    private JButton getBtn = new JButton(getImg);
    private JButton searchBtn = new JButton(searchImg);
    private JButton changePwdBtn = new JButton(changePwdImg);
    private JButton transFerBtn = new JButton(transFerImg);
    private JButton offBtn = new JButton(offImg);
    public MenuPanel(ATMFrame atmFrame){
        this.atmFrame =  atmFrame;
        this.setLayout(null);
        saveBtn.setBounds(0,170,140,50);
        getBtn.setBounds(0,240,140,50);
        transFerBtn.setBounds(0,310,140,50);
        changePwdBtn.setBounds(884,170,140,50);
        searchBtn.setBounds(884,240,140,50);
        offBtn.setBounds(884,310,140,50);
        this.add(saveBtn);
        this.add(getBtn);
        this.add(transFerBtn);
        this.add(changePwdBtn);
        this.add(searchBtn);
        this.add(offBtn);
        saveBtn.addActionListener(this);
        getBtn.addActionListener(this);
        transFerBtn.addActionListener(this);
        changePwdBtn.addActionListener(this);
        searchBtn.addActionListener(this);
       offBtn.addActionListener(this);
        this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == saveBtn){
            atmFrame.switchPanel("save");
        }else if(e.getSource() == getBtn){
            atmFrame.switchPanel("get");
        }else if(e.getSource() == transFerBtn){
            atmFrame.switchPanel("transFer");
        }else if(e.getSource() == changePwdBtn){
            atmFrame.switchPanel("changePwd");
        }else if(e.getSource() == searchBtn){
            atmFrame.getSearchPanel().sum();
            atmFrame.switchPanel("search");
        }else if(e.getSource() == offBtn){
            System.exit(0);
        }
    }
}
